<template>
  <div class="search-form pt6 pl2">
    <!-- <div class="content" v-if="visible && searchFormRes?.length >3">
      <el-col :xs="24">
        <Form :formDatas="searchFormRes" @handle-form-value="handleFormValue" />
      </el-col>
      <el-col  class="text-right flex justify-end pb4">
        <div  v-if="searchForm?.length > 3&&isAdvancedSearch" class="header-r mr2 " @click="handleAdvancedSearch">
          收起  <el-icon ><ArrowUp/></el-icon>
        </div>
        <el-button type="primary" size="small"  @click="emits('handleSearch', searchFormParams)">查询</el-button>
        <el-button type="" size="small"  @click="handleReset">重置</el-button>
      </el-col>
    </div> -->

    <div class="content">
      <el-row class="flex justify-between">
        <el-col :span="24">
          <Form :formDatas="searchFormRes" @handle-form-value="handleFormValue">
            <el-col style="display: flex; flex: 1; justify-content: flex-end;min-width: 200px;padding-bottom: 10px;">
              <div
                v-if="searchForm?.length > 3 && !isAdvancedSearch"
                class="header-r mr2"
                @click="handleAdvancedSearch"
              >
                展开 <el-icon><ArrowDown /></el-icon>
              </div>
              <div v-if="isAdvancedSearch" class="header-r mr2" @click="handleAdvancedSearch">
                收起 <el-icon><ArrowUp /></el-icon>
              </div>
              <el-button
                type="primary"
                size="small"
                @click="emits('handleSearch', searchFormParams)"
                >查询</el-button
              >
              <el-button type="" size="small" @click="handleReset">重置</el-button>
            </el-col>
          </Form>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ComputedRef, ref, defineEmits } from 'vue';
import { Form } from '@/components/Form';
import { computed } from 'vue';
import type { FormInstance } from 'element-plus';
const emits = defineEmits(['handleSearch', 'handleReset', 'chanFormValue', 'handleResetFormDatas']);

const ruleFormRef = ref<FormInstance>();
// interface Props {
//   title?: string;
// }

// withDefaults(defineProps<Props>(), {
//   title: '数据筛选'
// });
const props = defineProps({
  searchForm: {
    type: Array,
    required: true
  }
});
let searchFormParams = ref({});
const handleFormValue = (value: {}) => {
  searchFormParams.value = value;
  emits('chanFormValue', value);
};
const visible = ref(true);
const isAdvancedSearch = ref(false);

let searchFormRes: unknown[] | ComputedRef<unknown[]> = [];
searchFormRes = computed(() =>
  isAdvancedSearch.value ? props.searchForm : props.searchForm.slice(0, 3)
);

//
const handleReset = () => {
  emits('handleReset');
  emits('handleResetFormDatas');
};
// const searchIcon = useIcon({ name: 'el-icon-search' });
// const clearIcon = useIcon({ name: 'local-icon-clear' });
const handleAdvancedSearch = () => {
  isAdvancedSearch.value = !isAdvancedSearch.value;
};
const onShow = () => {
  visible.value = !visible.value;
};
</script>

<style lang="scss">
.search-form {
  background: var(--el-bg-color-overlay);
  border-radius: 4px;
  color: var(--el-text-color-primary);
  margin-bottom: 10px;
  font-size: 15px;
  font-weight: 600;
  padding-right: 20px;
  // :deep(.header) {
  //   display: flex;
  //   justify-content: space-between;
  //   .header-l {
  //     display: flex;
  //     align-items: center;
  //     font-size: 15px;
  //     font-weight: 600;
  //     &::before {
  //       display: inline-block;
  //       content: '';
  //       width: 4px;
  //       height: 50%;
  //       margin-right: 5px;
  //       background-color: var(--el-color-primary);
  //     }
  //   }
  //   .header-r {
  //     .el-button {
  //       margin-left: 10px;
  //       margin-bottom: 10px;
  //     }
  //   }
  // }
  // :deep(.content) {
  //   display: flex;
  //   justify-content: space-between;
  //   border-radius: 4px;
  //   padding: 15px 10px 0;
  //   background-color: var(--el-fill-color-lighter);
  //   .el-form-item {
  //     margin-bottom: 15px;
  //   }
  // }
  .el-form--inline .el-form-item {
    margin-right: 16px;
  }
  .header-r {
    color: #4880ff;
    cursor: pointer;
  }
}
.dark .search-form .content {
  background-color: var(--el-fill-color-light);
}
// .el-button--info {
//   background-color: #fff;
//   border: none;
//   color: #1a1919;
//   border: 1px solid #ccc;
// }
// .el-button:hover {
//   background-color: #fff;
//   color: #000;
// }
// .el-button:active {
//   background-color: #fff;
//   border: none;
//   color: #000;
//   border: 1px solid #ccc;
// }
</style>
